﻿using Entitas;
using UnityEngine;

public sealed class TransformComponent : IComponent
{
    public Vector3 position;
    public Vector3 forward;
    public SmootherForward smootherForward;

    public Vector3 LocalToWorld(Vector3 local)
    {
        Matrix4x4 trs = Matrix4x4.TRS(position, Quaternion.LookRotation(smootherForward.smootherForward, Vector3.up),
            Vector3.one);

        return trs * new Vector4(local.x, local.y, local.z, 1);
    }

    public Vector3 WorldToLocal(Vector3 world)
    {
        Matrix4x4 trs = Matrix4x4.TRS(position, Quaternion.LookRotation(smootherForward.smootherForward, Vector3.up),
            Vector3.one);

        return trs.inverse * new Vector4(world.x, world.y, world.z, 1);
    }
}